package com.leps.nq.op.controller;

import com.leps.nq.common.aspect.Log;
import com.leps.nq.common.enums.BusinessType;
import com.leps.nq.common.vo.PageVo;
import com.leps.nq.common.vo.R;
import com.leps.nq.common.vo.RBuilder;
import com.leps.nq.op.entity.OpMonthlyTask;
import com.leps.nq.op.service.IOpMonthlyTaskService;
import com.leps.nq.op.vo.MonthlyTaskQueryModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 月度任务表 前端控制器
 * </p>
 *
 * @author hex
 * @since 2022-05-22
 */
@RestController
@RequestMapping("/op/op-monthly-task")
@Api(tags = "月度任务管理")
public class OpMonthlyTaskController {
    @Autowired
    IOpMonthlyTaskService monthlyTaskService;

    @GetMapping
    @ApiOperation("月度任务列表")
    public R<PageVo<OpMonthlyTask>> list(MonthlyTaskQueryModel queryModel) {
        PageVo<OpMonthlyTask> pageVo = this.monthlyTaskService.pageByQueryModel(queryModel);
        return RBuilder.ok(pageVo);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询月度任务信息")
    public R<OpMonthlyTask> getById(@PathVariable Long id) {
        return RBuilder.ok(this.monthlyTaskService.getById(id));
    }

    @PostMapping
    @ApiOperation("新建月度任务")
    @Log(title = "月度任务", businessType = BusinessType.INSERT)
    public R<?> save(@RequestBody OpMonthlyTask monthlyTask) {
        return RBuilder.ofBoolean(this.monthlyTaskService.save(monthlyTask));
    }

    @PutMapping
    @ApiOperation("修改月度任务")
    @Log(title = "月度任务", businessType = BusinessType.UPDATE)
    public R<?> update(@RequestBody OpMonthlyTask monthlyTask) {
        return RBuilder.ofBoolean(this.monthlyTaskService.updateById(monthlyTask));
    }

    @DeleteMapping
    @ApiOperation("删除月度任务")
    @Log(title = "月度任务", businessType = BusinessType.DELETE)
    public R<?> remove(@RequestBody List<Long> ids) {
        return RBuilder.ofBoolean(this.monthlyTaskService.removeBatchByIds(ids));
    }
}
